package com.kotiln.lgc.lib_base.helper

import android.content.Context
import android.media.SoundPool

/**
 *@fileName SoundHelper
 *@date2021/1/29  15:54
 *@author SoundHelper$
 *@describe TODO
 *@desc 播放铃声
 */
object SoundPoolHelper {

    private lateinit var mContext: Context
    private lateinit var mSoundPool: SoundPool

    fun init(mContext: Context) {
        this.mContext = mContext
        mSoundPool = SoundPool.Builder().setMaxStreams(1).build()
    }

    //播放
    fun play(resId: Int) {
        val poolId: Int = mSoundPool.load(mContext, resId, 1)
        mSoundPool.setOnLoadCompleteListener { _, _, status ->

                if (status == 0) {
                    /**
                     * 参数一:ID
                     * 参数二:左音量 0.0-1.0
                     * 参数三:右音量 0.0-1.0
                     * 参数四:优先级
                     * 参数五:重复数
                     * 参数六:速率  0.5-2.0
                     */
                    mSoundPool.play(poolId, 1f, 1f, 1, 0, 1f)
                }

            }

        }

}